{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "Python 3.7.4 64-bit ('venv')",
   "display_name": "Python 3.7.4 64-bit ('venv')",
   "metadata": {
    "interpreter": {
     "hash": "5ca8c05cb09fcbad96834999439e83bae350d61da9ba42ce02e15527d4ec2089"
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "source": [
    "import datetime\n",
    "import time\n",
    "from logzero import logger\n",
    "from apscheduler.schedulers.background import BackgroundScheduler\n",
    "from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor"
   ],
   "cell_type": "code",
   "metadata": {},
   "execution_count": 19,
   "outputs": []
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "def func():\n",
    "    now = datetime.datetime.now()\n",
    "   \n",
    "    logger.info('do func2 time：')\n",
    "\n",
    "def func2():\n",
    "    now = datetime.datetime.now()\n",
    "    logger.info('do func2 time：')\n",
    "    time.sleep(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "def dojob():\n",
    "    executors = {\n",
    "        'default': ThreadPoolExecutor(20),\n",
    "        'processpool': ProcessPoolExecutor(5)\n",
    "    }\n",
    "    #创建调度器：BlockingScheduler\n",
    "    scheduler = BackgroundScheduler(executors=executors)\n",
    " \n",
    "    #添加任务,时间间隔2S\n",
    "    scheduler.add_job(func, 'interval', seconds=2, id='test_job1')\n",
    "    #添加任务,时间间隔5S\n",
    "    scheduler.add_job(func2, 'interval', seconds=3, id='test_job2')\n",
    "    scheduler.start()\n",
    "\n",
    "dojob()"
   ]
  }
 ]
}